package com.gnerv.sylvanas.business.manage.storage;

import com.gnerv.sylvanas.business.manage.model.dto.RoleDTO;
import com.gnerv.sylvanas.business.manage.model.entity.Role;
import com.gnerv.sylvanas.business.manage.repository.mapper.RoleApiMapper;
import com.gnerv.sylvanas.business.manage.repository.mapper.RoleAccountMapper;
import com.gnerv.sylvanas.business.manage.repository.mapper.RoleMapper;
import com.gnerv.sylvanas.business.manage.repository.mapper.RoleViewMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author Gnerv LiGen
 */
@Service
@AllArgsConstructor
public class RoleStorageService {

    private final RoleMapper roleMapper;
    private final RoleAccountMapper roleAccountMapper;
    private final RoleApiMapper roleApiMapper;
    private final RoleViewMapper roleViewMapper;

    
    public int insert(Role role) {
        return roleMapper.insert(role);
    }

    
    public int deleteByUkId(String ukId) {
        return roleMapper.deleteByUkId(ukId);
    }

    
    public int updateByUkId(Role role) {
        return roleMapper.updateByUkId(role);
    }

    
    public RoleDTO selectByUkId(String ukId) {
        return roleMapper.selectByUkId(ukId);
    }

    
    public List<RoleDTO> selectListByName(String name) {
        return roleMapper.selectListByName(name);
    }

    
    public List<String> selectListUkIdByAccountUkId(String accountUkId) {
        return roleMapper.selectListUkIdByAccountUkId(accountUkId);
    }

    
    public int bindAccount(String roleUkId, Set<String> accountUkIdList, String creator) {
        return roleAccountMapper.insertRoleAccount(roleUkId, accountUkIdList, creator);
    }

    
    public int bindApi(String roleUkId, Set<String> apiUkIdList, String creator) {
        return roleApiMapper.insertRoleApi(roleUkId, apiUkIdList,  creator);
    }

    
    public int bindView(String roleUkId, Set<String> viewUkIdList, String creator) {
        return roleViewMapper.insertRoleView(roleUkId, viewUkIdList, creator);
    }

    
    public int unbindAccount(String roleUkId) {
        return roleAccountMapper.deleteByRoleUkId(roleUkId);
    }

    
    public int unbindApi(String roleUkId) {
        return roleApiMapper.deleteByRoleUkId(roleUkId);
    }

    
    public int unbindView(String roleUkId) {
        return roleViewMapper.deleteByRoleUkId(roleUkId);
    }
}
